package com.jinghong.epidemiccontrolproject.service.impi;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jinghong.epidemiccontrolproject.mapper.RegionMapper;
import com.jinghong.epidemiccontrolproject.pojo.PageBean;
import com.jinghong.epidemiccontrolproject.pojo.Region;
import com.jinghong.epidemiccontrolproject.service.RegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ClassName:RegionServiceImpi
 * Package:com.jinghong.epidemiccontrolproject.service.impi
 * Description:
 *
 * @Author: 寻月君子
 * @CreatTime:2024/1/19 23:06
 * Version:1.0
 */
@Service
public class RegionServiceImpi implements RegionService {
    @Autowired
    private RegionMapper regionMapper;


    @Override
    public PageBean page(Integer page, Integer pageSize, String name) {
        //1. 设置分页参数
        PageHelper.startPage(page,pageSize);

        //2. 执行查询
        List<Region> regionList = regionMapper.list(name);
        Page<Region> p = (Page<Region>)regionList;

        //3. 封装PageBean对象
        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;
    }

    @Override
    public void add(String name) {
        Integer certifyNum = 0;
        Integer recoverNum = 0;
        Integer deathNum = 0;
        regionMapper.add(name,certifyNum,recoverNum,deathNum);
    }
}
